<template>
  <!-- 对话框(添加 / 修改) -->
  <el-dialog :title="title" :visible.sync="show" width="500px" append-to-body :before-close="cancel">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                      <el-form-item label="异动id" prop="changeId">
                        <el-input v-model="form.changeId" placeholder="请输入异动id" />
                      </el-form-item>
                  <el-form-item label="原状态" prop="oldStatus">
                    <el-select v-model="form.oldStatus" placeholder="请选择原状态">
                          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.STUDENT_CHECK_STATUS)"
                                     :key="dict.value" :label="dict.label" :value="dict.value" />
                    </el-select>
                  </el-form-item>
                  <el-form-item label="新状态" prop="newStatus">
                    <el-select v-model="form.newStatus" placeholder="请选择新状态">
                          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.STUDENT_CHECK_STATUS)"
                                     :key="dict.value" :label="dict.label" :value="dict.value" />
                    </el-select>
                  </el-form-item>
                      <el-form-item label="审核用户" prop="checkUser">
                        <el-input v-model="form.checkUser" placeholder="请输入审核用户" />
                      </el-form-item>
                  <el-form-item label="审核时间" prop="checkTime">
                    <el-date-picker clearable v-model="form.checkTime" type="date" value-format="timestamp" placeholder="选择审核时间" />
                  </el-form-item>
                      <el-form-item label="机构编号" prop="orgId">
                        <el-input v-model="form.orgId" placeholder="请输入机构编号" />
                      </el-form-item>
                      <el-form-item label="备注" prop="remark">
                        <el-input v-model="form.remark" placeholder="请输入备注" />
                      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { createStudentChangeLog, updateStudentChangeLog } from "@/api/collegebase/studentChangeLog";

  export default {
    name: "StudentChangeLogEdit",
    components: {
    },
    data() {
      return {
        // 表单参数
        form: {},
        // 表单校验
        rules: {
                        changeId: [{ required: true, message: "异动id不能为空", trigger: "blur" }],
                        oldStatus: [{ required: true, message: "原状态不能为空", trigger: "change" }],
                        newStatus: [{ required: true, message: "新状态不能为空", trigger: "change" }],
        }
      };
    },
    created() {},
    props: {
      // 是否显示弹出层
      show: {
        type: Boolean,
        default: false
      },
      // 显示弹出层标题
      title: {
        type: String,
        default: ''
      }
    },
    methods: {
      /** 初始化编辑的数据**/
      initData(rowData) {
        this.reset();
        if (rowData && rowData.id) {
          this.form = rowData;
          this.form.datetimerange = [this.form.startTime,this.form.endTime]
        }
      },
      /** 取消按钮 */
      cancel() {
        this.$emit('update:show', false)
        this.reset();
      },
      /** 表单重置 */
      reset() {
        this.form = {
                            id: undefined,
                            changeId: undefined,
                            oldStatus: undefined,
                            newStatus: undefined,
                            checkUser: undefined,
                            checkTime: undefined,
                            orgId: undefined,
                            remark: undefined,
        };
        this.resetForm("form");
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (!valid) {
            return;
          }
          // 修改的提交
          if (this.form.id != null) {
            updateStudentChangeLog(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.cancel();
              this.$emit('success')
            });
            return;
          }
          // 添加的提交
          createStudentChangeLog(this.form).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.cancel();
            this.$emit('success')
          });
        });
      },

    }
  };
</script>